package mx.itschapala.dsw2.biblioteca8a.dao;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import mx.itschapala.dsw2.biblioteca8a.modelo.Autor;

    
/**
 *
 * @author Raven
 */
@Stateless
public class AutorDao extends AbstractDao<Autor> implements AutorDaoLocal {
    @PersistenceContext(unitName = "Biblioteca8A-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public AutorDao() {
        super(Autor.class);
    }

    @Override
    public boolean findDuplicity(Autor author) {
      // selecionar consulta
        Query q=em.createNamedQuery("Autor.findDuplicity");
       //poner parametros
        q.setParameter("nombre", author.getNombre());
        q.setParameter("apellidoPaterno", author.getApellidoPaterno());
        q.setParameter("apellidoMaterno", author.getApellidoMaterno());
        //ejecutar la consulta
        return !q.getResultList().isEmpty();
    }


//    public Autor findDuplicity(Autor author) {
//       
//        return null;
//    }

    @Override
    public Autor findDuplicity(AutorDao author) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}